package com.baidu.speech.qr_code.ui.Main;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.baidu.speech.qr_code.R;
import com.baidu.speech.qr_code.ui.Entity_class.Password;

import org.litepal.LitePal;
import org.litepal.crud.LitePalSupport;

import java.util.List;

public class MainActivity_register extends AppCompatActivity{

    private EditText et_sign_in_register;
    private EditText et_passwoord_register;
    private EditText et_passwoord_register2;
    private Button bu_sign_in_register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_register);
        initView();
        List<Password>passwords=LitePal.findAll(Password.class);
        for (Password password:passwords){
            Log.d("TAG", "onCreate账号"+password.getSign_in());
            Log.d("TAG", "onCreate密码"+password.getPassword());
        }
    }

    private void initView() {
        et_sign_in_register = (EditText) findViewById(R.id.et_sign_in_register);
        et_passwoord_register = (EditText) findViewById(R.id.et_passwoord_register);
        et_passwoord_register2 = (EditText) findViewById(R.id.et_passwoord_register2);
        bu_sign_in_register = (Button) findViewById(R.id.bu_sign_in_register);
        bu_sign_in_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if (et_sign_in_register.getText().toString().trim().equals("")||et_passwoord_register.getText().toString().equals("")){
                   Toast.makeText(MainActivity_register.this, "请填写账号、密码", Toast.LENGTH_SHORT).show();
               }else if (et_passwoord_register.getText().toString().trim().equals(et_passwoord_register2.getText().toString().trim())){
                       Password password=new Password();
                       password.setSign_in(et_sign_in_register.getText().toString().trim());
                       password.setPassword(et_passwoord_register.getText().toString().trim());
                       password.setConfirm_password(et_passwoord_register2.getText().toString().trim());
                       password.save();
                       Log.e("TAG", "onClick"+password.getSign_in()+"\t"+password.getPassword()+"\t"+password.getConfirm_password());
                       Toast.makeText(MainActivity_register.this, "注册成功", Toast.LENGTH_SHORT).show();
                       finish();
                   }else{
                       Toast.makeText(MainActivity_register.this, "两次输入密码不一致，请重新输入", Toast.LENGTH_SHORT).show();
                   }
            }
        });
    }
}